package com.example.diagnodroid.connexion;

import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.provider.Settings;

public class WifiTracker extends Service {

	private final Context mContext;

	// flag for Wifi status
	boolean isWifiEnabled = false;

	// Declaring a wifi Manager
	protected WifiManager wifiManager;
	
	// Declaring Wifi Info
	WifiInfo info;

	public WifiTracker(Context context) {
		this.mContext = context;
		getWifiInfos();
	}

	public void getWifiInfos() {
		
			wifiManager = (WifiManager) mContext.getSystemService(WIFI_SERVICE);

			// getting GPS status
			isWifiEnabled = wifiManager.isWifiEnabled();

			// if GPS Enabled get lat/long using GPS Services
			if (isWifiEnabled) {
				info = wifiManager.getConnectionInfo();	
			} else {
				this.showSettingsAlert(); 
			}			

	}


	/**
	 * Function to show settings alert dialog On pressing Settings button will
	 * lauch Settings Options
	 * */
	public void showSettingsAlert() {
		AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

		// Setting Dialog Title
		alertDialog.setTitle("Wifi is settings");

		// Setting Dialog Message
		alertDialog
				.setMessage("Wifi is not enabled. Do you want to go to settings menu?");

		// On pressing Settings button
		alertDialog.setPositiveButton("Settings",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						Intent intent = new Intent(
								Settings.ACTION_WIFI_SETTINGS);
						mContext.startActivity(intent);
					}
				});

		// on pressing cancel button
		alertDialog.setNegativeButton("Cancel",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				});

		// Showing Alert Message
		alertDialog.show();
	}

	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

}
